package bancoArtigos.dao;

import java.sql.Connection;
import javax.naming.InitialContext;
import javax.sql.DataSource;

public class BaseDAO {

    private DataSource ds;

//------------------------------------------------------------------------------------------------------------
    public BaseDAO() {
        try {
            InitialContext cxt = new InitialContext();

            if (cxt == null) {
                System.out.println("[DAO.constructor] Falha no InitialContext.");
            }

            ds = (DataSource) cxt.lookup("java:comp/env/jdbc/papers");

        } catch (Exception e) {
            System.out.println("[DAO.constructor] Excessão: " + e.getMessage());
        }
    }
//------------------------------------------------------------------------------------------------------------
    public Connection getConnection(){
//        System.out.println("BaseDAO: Vai criar conexão...");
        try{
            return ds.getConnection();
        }catch(Exception e){
            System.out.println("BaseDAO: "+e);
        }
        return null;
    }
//------------------------------------------------------------------------------------------------------------
}
